<template>
  <el-form-item>
    <el-button type="primary" icon="el-icon-error" @click="clearSearchForm">
      重置
    </el-button>
    <el-button type="primary" icon="el-icon-search" @click="fetchList">
      查询
    </el-button>
    <el-button
      v-if="importFlag"
      type="primary"
      icon="el-icon-download"
      @click="downloadTemplate"
    >
      下载模板
    </el-button>
    <el-button
      v-if="importFlag"
      type="primary"
      icon="el-icon-upload2"
    >
      导入
    </el-button>
    <el-button
      type="primary"
      v-if="exportFlag"
      icon="el-icon-download"
      @click="exportMethod"
    >
      导出
    </el-button>
    <el-button v-if="addFlag" type="primary" @click="addFun">新增</el-button>
  </el-form-item>
</template>
<script>
export default {
  name: 'SearchButtons',
  props: {
    importFlag: {
      type: Boolean,
      default: false
    },
    exportFlag: {
      type: Boolean,
      default: false
    },
    fetchData: {
      type: Function
    },
    templateUrl: {
      type: String,
      default: null
    },
    exportExcel: {
      type: Function,
      default: null
    },
    addFun: {
      type: Function,
      default: null
    },
    addFlag: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    clearSearchForm() {
      this.$parent.$parent.searchForm = {}
      this.fetchList()
    },
    fetchList() {
      this.fetchData()
    },
    downloadTemplate() {
      window.location.href = this.templateUrl
    },
    exportMethod() {
      this.export2Excel()
    }
  }
}
</script>
